import { valIsEmpty } from "../../../../../utils/utils"

Component({
	properties: {
		required: {
			type: Boolean,
			value: false,
		},
		validMessage: {
			type: String,
			value: "此项不能为空",
		},
		value: {
			type: [String, Number, Array, Object],
			value: ""
		},
		customValid: {
			type: Function,
			value: null,
		}
	},
	data: {},
	methods: {
		//表单校验
		handleVerify() {
			//自定义表单校验规则
			if (this.data.customValid) {
				return this.data.customValid(this.data.value)
			}
			if (this.data.required && valIsEmpty(this.data.value)) {
				wx.showToast({
					title: this.data.validMessage,
					icon: "none",
				})
				return false
			}
			return true
		},
	},
})
